

package com.depthsdata.coe.dao.impl ;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.beanutils.PropertyUtils;

import org.springframework.jdbc.core.RowMapper;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;


import com.depthsdata.coe.dao.BusinessNode;
import com.depthsdata.coe.dao.BusinessNodeDAOQueryBean;
import com.depthsdata.coe.dao.IBusinessNodeDAO;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2019-12-27 11:41:50
  * Warning ! This file will be overwrite when regenerate !
  * 
 */

public class AbstractBusinessNodeDAOJdbcImpl 
    extends AbstractSpringDAO implements IBusinessNodeDAO{
    
            
    	
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
			
			
		
		
		
	    
    					
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
    public static final String[] ENTITY_FIELDS = new String[] { Id,BusinessProcessId,ParentBusinessNodeId,PreBusinesNodeId,NextBusinessNodeId,BusinessNodeName,BusinessNodeType,DeleteFlag,Status,Remarks,ProcessDiagramNodeId };
	
	public static final String[] ENTITY_PROPERTIES = new String[] {_DataObjectProperty.Id,_DataObjectProperty.BusinessProcessId,_DataObjectProperty.ParentBusinessNodeId,_DataObjectProperty.PreBusinesNodeId,_DataObjectProperty.NextBusinessNodeId,_DataObjectProperty.BusinessNodeName,_DataObjectProperty.BusinessNodeType,_DataObjectProperty.DeleteFlag,_DataObjectProperty.Status,_DataObjectProperty.Remarks,_DataObjectProperty.ProcessDiagramNodeId};
	
	public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
	
	public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};
	
	private static String relatedJoinSQL = null;
	
	private static String basicFilterSQL = null;
	
	private DataAccessObjectHelper<BusinessNode, BusinessNodeDAOQueryBean> daoHelper;
	
	public AbstractBusinessNodeDAOJdbcImpl() {
		super();
		daoHelper = new DataAccessObjectHelper<BusinessNode, BusinessNodeDAOQueryBean>(this);
	}
	
	protected String getEntityName() {
		return EntityName;
	}

	protected String[] getEntityFields() {
		return ENTITY_FIELDS;
	}

	protected String[] getEntityProperties() {
		return ENTITY_PROPERTIES;
	}

	protected String[] getEntityPKFields() {
		return ENTITY_PK_FIELDS;
	}
	
	protected String[] getEntityAutoGenPKFields(){
		return ENTITY_AUTO_GEN_PK_FIELDS;
	}
	
	
	protected String[] getEntityUniqueFields() {
		return ENTITY_UNIQUE_FIELDS;
	}
	
	protected String getBaiscQueryFilter(){
	
		if(basicFilterSQL == null){
                        StringBuffer basicFilterSQLbuffer = new StringBuffer();
						
			basicFilterSQL = basicFilterSQLbuffer.toString();
		}
		
		return basicFilterSQL;
	}
	
	protected String getRelatedJoinSQL(){
		
		if(relatedJoinSQL == null){
			StringBuffer relatedJoinSQLBuffer = new StringBuffer();
			
						
			relatedJoinSQL = relatedJoinSQLBuffer.toString();
		}
		
		return relatedJoinSQL;
	}
	
    /**
	 * Check Data Unique
	 * @param aBusinessNode
	 * @throws Exception
	 */
	public boolean checkIsUnique(BusinessNode aBusinessNode) throws Exception{
	
		if(aBusinessNode == null){
			return true;
		}
	
		List valueList = new ArrayList();

		List pkValueList = new ArrayList();
		
		                
				
	    		
		pkValueList.add(aBusinessNode.getId());
				
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
		                
				
	    		
				
		return isUnique(valueList.toArray(new Object[valueList.size()]), pkValueList
				.toArray(new Object[pkValueList.size()]));
	
	}
	
	/**
	 * Insert Data
	 * @param aBusinessNode
	 * @throws Exception
	 */
	public void insert(BusinessNode aBusinessNode) throws Exception{
		
				
		super.doInsert(aBusinessNode);

	}

    /**
	 * Batch Insert Datas
	 * @param aBusinessNode
	 * @throws Exception
	 */
	public void batchInsert(BusinessNode[] aBusinessNodes) throws Exception{
		
		 super.doBatchInsert(aBusinessNodes);
		
	}

    /**
	 * Delete Data
	 * @param  final long id	 *
	 * @throws Exception
	 */
	public void delete( final long id ) throws Exception{

				
				super.doDeleteById(new Object[] {		
									
			new Long(id)
						
		});
				
	}
	
	/**
	 * Delete Datas
	 * @param queryBean 
	 * @throws Exception
	 */
	public void delete(BusinessNodeDAOQueryBean queryBean) throws Exception{
	
				
		super.doDeleteByQuery(queryBean);
				
	}
	
	public void delete(BusinessNode aBusinessNode) throws Exception {
				
				
									
						
					
				
		delete(aBusinessNode.getId());
		
	}
	
	/**
	 * Update Data Selective
	 * @param aBusinessNode
	 * @throws Exception
	 */
	public void update(BusinessNode aBusinessNode) throws Exception{
		
						
											
				
				
		if(aBusinessNode.getId() == 0){
			throw new Exception("Can not update object data whith out primary key value");
		}
				
		super.doUpdate(aBusinessNode);
		
		BusinessNode tempObj = findById(aBusinessNode.getId());
		
		if(tempObj != null){
			PropertyUtils.copyProperties(aBusinessNode, tempObj);
		}
	}
	
	/**
	 * Batch Update Datas
	 * @param aBusinessNodes[]
	 * @throws Exception
	 */
	public void batchUpdate(BusinessNode[] aBusinessNodes) throws Exception{
		
		super.doBatchUpdate(aBusinessNodes);

	}

    /**
	 * Update Data By Condictions
	 * @param aBusinessNode
	 * @param aValueCriteria 
	 * @param aTransaction
	 * @throws Exception
	 */
	public void update(BusinessNode aBusinessNode, BusinessNodeDAOQueryBean aQueryBean) throws Exception{
		
				
		super.doUpdateByQuery(aBusinessNode, aQueryBean);
		
	}
	
	/**
	 * Update Data By Condictions
	 * @param aQueryBean
	 * @throws Exception
	 */
	public void update(BusinessNodeDAOQueryBean aQueryBean) throws Exception {
		super.doUpdateByQuery(aQueryBean);
	}


    protected void checkNullValue(BusinessNode aBusinessNode) throws Exception{	
																																																																					
		if(aBusinessNode.getProcessDiagramNodeId() == null){
			throw new Exception("The BusinessNode.processDiagramNodeId value is not allow NULL");
		}
								
	}
	
	/**
	 * Get Data By ID
	 * @param  final long id	 * @return  ${businessObject.name}
	 * @throws Exception
	 */
	public BusinessNode findById( final long id) throws Exception{
		
		    	                
    	    	                		
		BusinessNodeDAOQueryBean queryBean = new BusinessNodeDAOQueryBean();
		
		BusinessNodeDAOQueryBean.Criteria  criteria = queryBean.createCriteria();
	
		                

		criteria.andIdEqualTo(id);
        
        
		//queryBean.setDistinct(true);
		
		BusinessNode[] BusinessNodes = query(queryBean);
		
		if(BusinessNodes.length == 0){
			return null;
		}
		else{
			return BusinessNodes[0];
		}
		
	}

    /**
	 * Query Data
	 * @param queryBean
	 * @return BusinessNode[]
	 * @throws Exception
	 */
	public BusinessNode[] query(BusinessNodeDAOQueryBean queryBean) throws Exception{
				
		List result = super
				.doQuery(queryBean, new JdbcBusinessNodeRowMapper());

		return (BusinessNode[]) result.toArray(new BusinessNode[result.size()]);
	}
	
	/**
	 * Query ${businessObject.name} Selective
	 * @param queryBean
	 * @return Map[]
	 * @model
	 * @throws Exception
	 */
	public Map<String,Object>[] querySelective(BusinessNodeDAOQueryBean queryBean)  throws Exception{
		
		if(queryBean.getSelectProperties().isEmpty()){
			queryBean.addAllSelectProperties();
		}
		
		return super.doQuerySelective(queryBean);
		
	}
	
	/**
	 * Query Data Count
	 * @param queryBean
	 * @return int
	 * @throws Exception
	 */
	public int queryCount(BusinessNodeDAOQueryBean queryBean) throws Exception{
		
		return super.doQueryCount(queryBean);
		
	}
	
	public void synchronize(BusinessNode[] aBusinessNodes, BusinessNodeDAOQueryBean queryBean)
			throws Exception {
		daoHelper.synchronize(aBusinessNodes,queryBean);
		
	}

	public void synchronize(BusinessNode[] aBusinessNodes,
			BusinessNodeDAOQueryBean queryBean,
			net.dao.IDataAccessInterface.ISynchronizeCallback<BusinessNode> callBack)
			throws Exception {
		daoHelper.synchronize(aBusinessNodes,queryBean,callBack);
	}

    
     public static class JdbcBusinessNodeRowMapper implements
			RowMapper<BusinessNode> {

		public BusinessNode mapRow(ResultSet resultSet, int arg1) throws SQLException {
			BusinessNode object = new BusinessNode();

			int columnIndex = 1;
			
			int __dataType;
			
			try{
													
	            	            
				Object id = null;
				
								
				id =  resultSet.getObject(columnIndex++);
				
				               
				object.setIdNull(resultSet.getBoolean(columnIndex++));
				
				if(id != null){
				
                    setBeanValue(object, _DataObjectProperty.Id,id);
				}
				
					
	            	            
				Object businessProcessId = null;
				
								
				businessProcessId =  resultSet.getObject(columnIndex++);
				
				               
				object.setBusinessProcessIdNull(resultSet.getBoolean(columnIndex++));
				
				if(businessProcessId != null){
				
                    setBeanValue(object, _DataObjectProperty.BusinessProcessId,businessProcessId);
				}
				
					
	            	            
				Object parentBusinessNodeId = null;
				
								
				parentBusinessNodeId =  resultSet.getObject(columnIndex++);
				
				               
				object.setParentBusinessNodeIdNull(resultSet.getBoolean(columnIndex++));
				
				if(parentBusinessNodeId != null){
				
                    setBeanValue(object, _DataObjectProperty.ParentBusinessNodeId,parentBusinessNodeId);
				}
				
					
	            	            
				Object preBusinesNodeId = null;
				
								
				preBusinesNodeId =  resultSet.getObject(columnIndex++);
				
				               
				object.setPreBusinesNodeIdNull(resultSet.getBoolean(columnIndex++));
				
				if(preBusinesNodeId != null){
				
                    setBeanValue(object, _DataObjectProperty.PreBusinesNodeId,preBusinesNodeId);
				}
				
					
	            	            
				Object nextBusinessNodeId = null;
				
								
				nextBusinessNodeId =  resultSet.getObject(columnIndex++);
				
				               
				object.setNextBusinessNodeIdNull(resultSet.getBoolean(columnIndex++));
				
				if(nextBusinessNodeId != null){
				
                    setBeanValue(object, _DataObjectProperty.NextBusinessNodeId,nextBusinessNodeId);
				}
				
					
	            	            
				Object businessNodeName = null;
				
								
				businessNodeName =  resultSet.getObject(columnIndex++);
				
				               
				object.setBusinessNodeNameNull(resultSet.getBoolean(columnIndex++));
				
				if(businessNodeName != null){
				
                    setBeanValue(object, _DataObjectProperty.BusinessNodeName,businessNodeName);
				}
				
					
	            	            
				Object businessNodeType = null;
				
								
				businessNodeType =  resultSet.getObject(columnIndex++);
				
				               
				object.setBusinessNodeTypeNull(resultSet.getBoolean(columnIndex++));
				
				if(businessNodeType != null){
				
                    setBeanValue(object, _DataObjectProperty.BusinessNodeType,businessNodeType);
				}
				
					
	            	            
				Object deleteFlag = null;
				
								
				deleteFlag =  resultSet.getObject(columnIndex++);
				
				               
				object.setDeleteFlagNull(resultSet.getBoolean(columnIndex++));
				
				if(deleteFlag != null){
				
                    setBeanValue(object, _DataObjectProperty.DeleteFlag,deleteFlag);
				}
				
					
	            	            
				Object status = null;
				
								
				status =  resultSet.getObject(columnIndex++);
				
				               
				object.setStatusNull(resultSet.getBoolean(columnIndex++));
				
				if(status != null){
				
                    setBeanValue(object, _DataObjectProperty.Status,status);
				}
				
					
	            	            
				Object remarks = null;
				
								
				remarks =  resultSet.getObject(columnIndex++);
				
				               
				object.setRemarksNull(resultSet.getBoolean(columnIndex++));
				
				if(remarks != null){
				
                    setBeanValue(object, _DataObjectProperty.Remarks,remarks);
				}
				
					
	            	            
				Object processDiagramNodeId = null;
				
								
				processDiagramNodeId =  resultSet.getObject(columnIndex++);
				
				               
				object.setProcessDiagramNodeIdNull(resultSet.getBoolean(columnIndex++));
				
				if(processDiagramNodeId != null){
				
                    setBeanValue(object, _DataObjectProperty.ProcessDiagramNodeId,processDiagramNodeId);
				}
				
								
								
				return object;
			}catch(Exception e){
				throw new SQLException(e.getMessage());
			}
		}

	}
	
}